#include "AbstractFactory.h"
#include "AbstractProductA.h"
#include "AbstractProductB.h"
#include "ConcreteFactory.h"
/**
 * The client code works with factories and products only through abstract
 * types: AbstractFactory and AbstractProduct. This lets you pass any factory or
 * product subclass to the client code without breaking it.
 * 抽象工厂：是通过具体的工厂，通过基础接口生成具体的抽象产品。
 * 具体的抽象产品，调用接口，实现逻辑组织
 */

void ClientCode(const AbstractFactory& factory) {
	const AbstractProductA* product_a = factory.CreateProductA();
	const AbstractProductB* product_b = factory.CreateProductB();
	std::cout << product_b->UsefulFunctionB() << "\n";
	std::cout << product_b->AnotherUsefulFunctionB(*product_a) << "\n";
	delete product_a;
	delete product_b;
}

int main() {
	std::cout << "Client: Testing client code with the first factory type:\n";
	ConcreteFactory1* f1 = new ConcreteFactory1();
	ClientCode(*f1);
	delete f1;
	std::cout << std::endl;
	std::cout << "Client: Testing the same client code with the second factory type:\n";
	ConcreteFactory2* f2 = new ConcreteFactory2();
	ClientCode(*f2);
	delete f2;
	return 0;
}